﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AMRService.Base;
using AMRService.IDAL;
using AMRService.Models.ResponseModels.ModelHelper.Common;
using Newtonsoft.Json;

namespace AMRService.DAL
{
    public class AmrService : IAmrService
    {
        public async Task<T1> AmrCancelTask<T1>(long AmrId, Dictionary<string, string> HeaderList = null)
        {
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(AmrConfiguration.AmrConfig.BaseAddress);
                using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, AmrConfiguration.AmrConfig.Amr_CancelTask + "/" + AmrId);
                {
                    if (HeaderList != null)
                    {
                        foreach (var item in HeaderList)
                        {
                            request.Headers.Add(item.Key, item.Value);
                        }
                    }

                    using var response1 = await client.SendAsync(request);
                    {
                        var response2 = await response1.Content.ReadAsStringAsync();
                        var result = JsonConvert.DeserializeObject<T1>(response2);
                        return result;
                    }

                }
            }
        }

        public async Task<Root<List<Data>>> AmrOnLine(string BaseAddress, string OnLineUrl, Dictionary<string, string> HeaderList = null)
        {
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(BaseAddress);
                using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, OnLineUrl);
                {
                    if (HeaderList != null)
                    {
                        foreach (var item in HeaderList)
                        {
                            request.Headers.Add(item.Key, item.Value);
                        }
                    }
                    using var response1 = await client.SendAsync(request, HttpCompletionOption.ResponseContentRead);
                    {
                        string response2 = await response1.Content.ReadAsStringAsync();
                        var result = JsonConvert.DeserializeObject<Root<List<Data>>>(response2);
                        return result;
                    }

                }
            }
        }


        public Task AmrPause(long AmrId)
        {
            throw new NotImplementedException();
        }

        public Task AmrQueryTaskList()
        {
            throw new NotImplementedException();
        }

        public Task AmrResume(long AmrId)
        {
            throw new NotImplementedException();
        }

        public Task AmrTaskPut()
        {
            throw new NotImplementedException();
        }
    }
}
